package com.example.uitls;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.DisplayMetrics;

import java.util.Locale;

/**
 * Created by leonardo on 17/5/27.
 */

public class LanguageUtils {


    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
    private void setLanguage(Context context) {

        //读取SharedPreferences数据，默认选中第一项
        int language = (int) PreUtils.getParam(context,"language", 0);

        //根据读取到的数据，进行设置
        Resources resources = context.getResources();
        DisplayMetrics displayMetrics = resources.getDisplayMetrics();
        Configuration configuration = resources.getConfiguration();

        switch (language){
            case 0:
                configuration.setLocale(Locale.getDefault());
                break;
            case 1:
                configuration.setLocale( Locale.CHINESE);
                break;
            default:
                break;
        }

        resources.updateConfiguration(configuration,displayMetrics);

    }

}
